package com.cg.design.depthdesign.abstractfactory;

import com.cg.design.depthdesign.abstractfactory.app.Application;
import com.cg.design.depthdesign.abstractfactory.factories.GUIFactory;
import com.cg.design.depthdesign.abstractfactory.factories.MacOSFactory;
import com.cg.design.depthdesign.abstractfactory.factories.WindowsFactory;

/**
 * 创建型模式：AbstractFactory抽象工厂模式测试类
 * <p>
 * 抽象工厂模式是一种创建型设计模式，它能创建一系列相关的对象，而无需指定其具体类。
 *
 * @program: LeetCode->AbstractFactoryTest
 * @author: cg
 * @create: 2022-04-07 09:36
 **/
public class AbstractFactoryTest {

    /**
     * 应用程序根据配置或环境变量选择工厂类型并在运行时(通常在初始化阶段)创建它。
     *
     * @return
     */
    private static Application configureApplication() {
        Application app;
        GUIFactory factory;
        String osName = System.getProperty("os.name").toLowerCase();
        if (osName.contains("mac")) {
            factory = new MacOSFactory();
            app = new Application(factory);
        } else {
            factory = new WindowsFactory();
            app = new Application(factory);
        }
        return app;
    }

    public static void main(String[] args) {
        Application app = configureApplication();
        app.paint();
    }

}
